/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package no.saiboten.tourbuilder.user.controller;

import no.saiboten.tourbuilder.user.UserDAO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserDAO userDAO;

	@RequestMapping(method = RequestMethod.GET)
	public @ModelAttribute("user")
	ModelAndView getUser() {
		ModelAndView mav = new ModelAndView("user");
		mav.addObject("users", userDAO.getAllUsers());
		return mav;
	}

	@RequestMapping(value = "/get/{path}", method = RequestMethod.GET)
	public ModelAndView getUser(@PathVariable String path) {
		ModelAndView mav = new ModelAndView("user");
		mav.addObject("user", userDAO.getUser(path));
		return mav;
	}

}
